package com.oba.king.controlmanage.proxyproduct;

import java.util.List;

import com.oba.base.dao.DBDataModel;
import com.oba.base.interfaces.IBaseBo;
import com.oba.base.service.BaseBean;
import com.oba.king.controlmanage.ProxyContract;
import com.oba.king.datalib.productinfo.ProductInfo;

public class ProxyProductDetailsBean extends BaseBean<ProxyProductDetails, ProxyProductDetailsService>{
	private DBDataModel proxyProductData = DBDataModel.create();
	private ProxyProductDetails proxyProductDetails;
	private boolean showProxyProductDetails;
	private ProxyContract proxyContract;
	private ProductInfo productInfo;
	private List<ProxyProductDetails> list;
	
    private DBDataModel selectProductData = DBDataModel.create();
	private ProxyProductCondition proxyProductCondition; 
	public void doAddRow() {
		proxyProductDetails = new ProxyProductDetails();
		proxyProductDetails.setNewBo(true);
		proxyProductDetails.setChecked(true);
		if(this.proxyContract!=null){
		showProxyProductDetails = true;
		}
		List obj = (List) proxyProductData.getWrappedData();
		selectProductData.find(getService().getDao().buildSelectProducts((List<IBaseBo>)obj),5);
	}
	public void selectedProduct(){
		proxyProductDetails.setContract(getProxyContract());
		if(selectProductData.isRowAvailable()){
			productInfo=(ProductInfo)selectProductData.getRowData();
		}
		proxyProductDetails.setProduct(productInfo);
		list.add(proxyProductDetails);
		proxyProductData.setWrappedData(list);
		showProxyProductDetails = false;
	}

	public void doEditRow() {
		if (proxyProductData.isRowAvailable()) {
			proxyProductDetails = (ProxyProductDetails) proxyProductData.getRowData();
			proxyProductDetails.setChecked(true);
			//doFind();
		}
	}

	public void doDeleteRow() {
		if (proxyProductData.isRowAvailable()) {
			proxyProductDetails = (ProxyProductDetails) proxyProductData.getRowData();
			getService().del(proxyProductDetails);
			doFind();
		}
	}

	public void closeShowEdit() {
		showProxyProductDetails = false;
	}
	public void doSaveRow() {
		if (proxyProductData.isRowAvailable()) {
			proxyProductDetails = (ProxyProductDetails) proxyProductData.getRowData();
			proxyProductDetails.setChecked(false);
			getService().save(proxyProductDetails);
			doFind();
		}
	}
	@Override
	public String doFind() {
		list = getService().getDao().findDetailsList(this.getProxyContract());
		proxyProductData.setWrappedData(list);
		return null;
	}
	public void clearProxyContractCondition() {
		proxyProductCondition = new ProxyProductCondition();
	}
	public void findByCondition() {
		List obj = (List) proxyProductData.getWrappedData();
		selectProductData.find(getService().getDao().buildSelectProducts((List<IBaseBo>)obj,proxyProductCondition),5);
		//proxyProductData.find(getService().getDao().findByCondition(proxyProductCondition));
	}
	@Override
	public void init() {
		proxyContract=new ProxyContract();
		proxyProductCondition=new ProxyProductCondition();
		//List<ProxyProductDetails> list = getService().getDao().findDetailsList();
		//proxyProductData.find(getService().getDao().findAll());
		proxyProductDetails = new ProxyProductDetails();
		showProxyProductDetails = false;
	}
	public void initDetailsList(ProxyContract pContract) {
		proxyProductCondition=new ProxyProductCondition();
		list = getService().getDao().findDetailsList(pContract);
		proxyProductData.setWrappedData(list);
		proxyProductDetails = new ProxyProductDetails();
		showProxyProductDetails = false;
	}
	public DBDataModel getProxyProductData() {
		return proxyProductData;
	}
	public void setProxyProductData(DBDataModel proxyProductData) {
		this.proxyProductData = proxyProductData;
	}

	public ProxyProductDetails getProxyProductDetails() {
		return proxyProductDetails;
	}

	public void setProxyProductDetails(ProxyProductDetails proxyProductDetails) {
		this.proxyProductDetails = proxyProductDetails;
	}
	public boolean isShowProxyProductDetails() {
		return showProxyProductDetails;
	}
	public void setShowProxyProductDetails(boolean showProxyProductDetails) {
		this.showProxyProductDetails = showProxyProductDetails;
	}
	public ProxyContract getProxyContract() {
		return proxyContract;
	}

	public void setProxyContract(ProxyContract proxyContract) {
		this.proxyContract = proxyContract;
	}
	public ProxyProductCondition getProxyProductCondition() {
		return proxyProductCondition;
	}
	public void setProxyProductCondition(ProxyProductCondition proxyProductCondition) {
		this.proxyProductCondition = proxyProductCondition;
	}
	public ProductInfo getProductInfo() {
		return productInfo;
	}
	public void setProductInfo(ProductInfo productInfo) {
		this.productInfo = productInfo;
	}
	public List<ProxyProductDetails> getList() {
		return list;
	}
	public void setList(List<ProxyProductDetails> list) {
		this.list = list;
	}
	public DBDataModel getSelectProductData() {
		return selectProductData;
	}
	public void setSelectProductData(DBDataModel selectProductData) {
		this.selectProductData = selectProductData;
	}
}
